#include "cloudserver.h"
#include "ui_cloudserver.h"
#include <QByteArray>
#include <QDebug>
#include <QMessageBox>
#include <QStringList>
#include <QFile>
CloudServer::CloudServer(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::CloudServer)
{
    ui->setupUi(this);
    InitFormConfig();
    MyTcpServer::get_instance()
            ->listen(QHostAddress(ServerIp),ServerPort);
    DBControler::get_instance()
            ->_config();
}

CloudServer::~CloudServer()
{
    delete ui;
}

int CloudServer::InitFormConfig(QString FileName)
{
    QFile file(FileName);
    if(!file.open(QIODevice::ReadOnly)){
        QMessageBox::critical(this,"打开文件","失败");
        return 1;//文件不存在返回1
    }
    QByteArray ConfigData=file.readAll();
    QString Data(ConfigData);
    Data.replace("\r\n"," ");
    QStringList splitData=Data.split(' ');
    this->ServerIp=splitData[0];
    this->ServerPort=splitData[1].toUShort();
    return 0;
}

